# -*- coding: utf-8 -*-

from google.appengine.ext import db
from google.appengine.tools import bulkloader

class Blockerator(db.Model):
    mute = db.BooleanProperty(default = False)

class UserPrefs(db.Model):
    user = db.UserProperty()
    cs_name = db.StringProperty()
    ci_name = db.StringProperty()
    muter = db.ReferenceProperty(Blockerator)
    created = db.DateTimeProperty(auto_now_add = True)

class Message(db.Model):
    text = db.TextProperty()
    is_blocked = db.BooleanProperty(default = False)
    created = db.DateTimeProperty(auto_now_add = True)
    changed = db.DateTimeProperty(auto_now = True)
    person = db.ReferenceProperty(UserPrefs)

class BlockeratorExporter(bulkloader.Exporter):
    def __init__(self):
        bulkloader.Exporter.__init__(self, 'Blockerator', 
                                    [('__key__', str, None),
                                     ('mute', str, None)])

class MessageExporter(bulkloader.Exporter):
    def __init__(self):
        bulkloader.Exporter.__init__(self, 'Message',
                                     [('__key__', str, None),
                                      ('text', lambda x: x.encode('utf-8'), None),
                                      ('is_blocked', str, None),
                                      ('created', str, None),
                                      ('person', str, None),
                                     ])

class UserPrefsExporter(bulkloader.Exporter):
    def __init__(self):
        bulkloader.Exporter.__init__(self, 'UserPrefs',
                                     [('__key__', str, None),
                                      ('cs_name', lambda x: x.encode('utf-8'), None),
                                      ('muter', str, None),
                                     ])
exporters = [MessageExporter]
